package com.hzlx.badGoods.controller;

import java.util.List;
import java.io.IOException;

import com.hzlx.ResultDto;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.badGoods.domain.MesBadGoods;
import com.hzlx.badGoods.service.IMesBadGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

import javax.xml.transform.Result;

/**
 * 待处理残次品Controller
 * 
 * @author ruoyi
 * @date 2025-07-07
 */
@RestController
@RequestMapping("/quality")
public class MesBadGoodsController extends BaseController
{
    @Autowired
    private IMesBadGoodsService mesBadGoodsService;

    /**
     * 查询待处理残次品列表
     */
    @RequiresPermissions("quality-service:quality:goods:list")
    @GetMapping("/badGoods/list")
    public TableDataInfo list(MesBadGoods mesBadGoods)
    {
        startPage();
        List<MesBadGoods> list = mesBadGoodsService.selectMesBadGoodsList(mesBadGoods);
        return getDataTable(list);
    }

    /**
     * 导出待处理残次品列表
     */
    @RequiresPermissions("quality-service:quality:goods:export")
    @Log(title = "待处理残次品", businessType = BusinessType.EXPORT)
    @PostMapping("/badGoods/export")
    public void export(HttpServletResponse response, MesBadGoods mesBadGoods)
    {
        List<MesBadGoods> list = mesBadGoodsService.selectMesBadGoodsList(mesBadGoods);
        ExcelUtil<MesBadGoods> util = new ExcelUtil<MesBadGoods>(MesBadGoods.class);
        util.exportExcel(response, list, "待处理残次品数据");
    }

    /**
     * 获取待处理残次品详细信息
     */
    @RequiresPermissions("quality-service:quality:goods:query")
    @GetMapping(value = "/badGoods/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesBadGoodsService.selectMesBadGoodsById(id));
    }

    /**
     * 新增待处理残次品
     */
    @RequiresPermissions("quality-service:quality:goods:add")
    @Log(title = "待处理残次品", businessType = BusinessType.INSERT)
    @PostMapping("/badGoods")
    public AjaxResult add(@RequestBody MesBadGoods mesBadGoods)
    {
        return toAjax(mesBadGoodsService.insertMesBadGoods(mesBadGoods));
    }

    /**
     * 修改待处理残次品
     */
    @RequiresPermissions("quality-service:quality:goods:edit")
    @Log(title = "待处理残次品", businessType = BusinessType.UPDATE)
    @PutMapping("/badGoods")
    public AjaxResult edit(@RequestBody MesBadGoods mesBadGoods)
    {
        return toAjax(mesBadGoodsService.updateMesBadGoods(mesBadGoods));
    }

    /**
     * 删除待处理残次品
     */
    @RequiresPermissions("quality-service:quality:goods:remove")
    @Log(title = "待处理残次品", businessType = BusinessType.DELETE)
	@DeleteMapping("/badGoods/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesBadGoodsService.deleteMesBadGoodsByIds(ids));
    }

    @RequiresPermissions("quality-service:quality:goods:edit")
    @PostMapping("/badGoods/pass")
    public ResultDto<String> Pass(@RequestBody MesBadGoods mesBadGoods){
        return mesBadGoodsService.pass(mesBadGoods);
    }

    @RequiresPermissions("quality-service:quality:goods:edit")
    @PostMapping("/badGoods/fail")
    public ResultDto<String> Fail(@RequestBody MesBadGoods mesBadGoods){
        return mesBadGoodsService.fail(mesBadGoods);
    }
}
